package com.veo.controller;

import com.veo.entity.User;
import com.veo.exception.UserTooManyException;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Arrays;
import java.util.List;

@Controller
public class TableController {

    @GetMapping("/basic_table")
    public String basicTable(){
        return "table/basic_table";
    }

    @GetMapping("/dynamic_table")
    public String dynamicTable(Model mode){
        User user = new User("张三","123");
        User user1 = new User("李四","999");
        User user2 = new User("万物","995");
        User user3 = new User("小天","5785");
        User user4 = new User("大天","545");
        List<User> users = Arrays.asList(user, user1, user2, user3, user4);
        mode.addAttribute("users",users);

        //自定义全局异常responseStatus
        if (users.size()>3){
            throw new UserTooManyException();
        }
        return "table/dynamic_table";
    }

    @GetMapping("/editable_table")
    public String editableTable(@RequestParam("id")String id){
        //出现算术异常
        int i = 1/0;
        return "table/editable_table";
    }


    @GetMapping("/responsive_table")
    public String responsiveTable(){

        return "table/responsive_table";
    }


}
